//
//  IngredientsCollectionViewCell.m
//  Food
//
//  Created by dllo on 15/7/21.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "IngredientsCollectionViewCell.h"
#import "UIImageView+WebCache.h"
@implementation IngredientsCollectionViewCell

- (void)dealloc
{
    [_model release];
    [_lableName release];
    [_img release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.img = [[[UIImageView alloc] init] autorelease];
        //        self.img.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:self.img];
        self.lableName = [[[UILabel alloc] init] autorelease];
        //        self.name.backgroundColor = [UIColor orangeColor];
        self.lableName.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:self.lableName];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super applyLayoutAttributes:layoutAttributes];
    self.img.frame = CGRectMake(5, 0, layoutAttributes.size.height - 10, layoutAttributes.size.height - 10);
    self.lableName.frame = CGRectMake(self.img.frame.size.width, 0, layoutAttributes.size.width - self.img.frame.size.width - 5, layoutAttributes.size.height);
}

- (void)setModel:(IngredientsModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    [self.img sd_setImageWithURL:[NSURL URLWithString:model.imageFilename]];
    self.lableName.text = model.name;
}
@end
